Data types casting

[08/01/2023]

According to IEC 61131-3 there are different data types of the same size. For example WORD, INT and UINT are of 16 bits. The problem is that normally it is not allowed to cast one type on to another. It is not possible to assign a variable WORD to another variable of INT type. In order to do such assignment, You need to convert the data type.

VAR

input : WORD;

output : INT;

END_VAR

output := WORD_TO_INT(input);

There are sets of dedicated array instructions specific for each type. For example, using MAX_ARWORD, we get max value from within array but only of WORD type.

Sometimes, when building complex application You will need to think carefully what data types to use in order to easily manipulate Your data.